package com.hui.web;

import io.swagger.annotations.ApiOperation;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class JobLauncherController {
    private final JobLauncher jobLauncher;
    private final Job job;

    @Autowired
    public JobLauncherController(JobLauncher jobLauncher, Job job) {
        this.jobLauncher = jobLauncher;
        this.job = job;
    }

    @ApiOperation(value = "任务", notes = "任务")
    @GetMapping("/jobLauncher")
    public JobExecution handle() throws Exception {
        jobLauncher.run(job, new JobParameters());
        return null;
    }
}